package kdd.feature;

import java.sql.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class EssayAbstraction {
	Connection conn;
	public EssayAbstraction(Connection connection){
		conn = connection;
	}
	
	public ArrayList<String> getEssay(String projectid) throws SQLException{
		ArrayList<String> ret = new ArrayList<String>();
		PreparedStatement query = conn.prepareStatement(
				"SELECT essay FROM essays WHERE projectid=?");
		query.setString(1, projectid);
		ResultSet result = query.executeQuery();
		while (result.next())
			ret.add(result.getString(1));
		result.close();
		return ret;	
	}
	
	public int getTotalEssayLength(String projectid) throws SQLException{
		ArrayList<String> array = getEssay(projectid);
		int ret = 0;
		for (String essay: array) ret += essay.length();
		return ret;
	}

}
